Use case: Detect temperature thresholds (non-blocking) ¶
Note
In HAL2, threshold configuration is simplified: use the dedicated API
HAL_DTS_SetSensorThresholds(), which accepts High and Low thresholds directly in degrees Celsius. This replaces the manual calculation required in HAL1.
You can check your reference manual to get the formula used in HAL1 to convert register values to degrees Celsius.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
DTS_HandleTypeDef hdts;
int32_t temp;
HAL_DTS_Init(&hdts);
hdts.Init.HighThreshold = 100; /* register readable value that needs to be */
hdts.Init.LowThreshold = 10; /* calculated to select the desired threshold in degrees Celsius */
/* For example: Temperature: 40
register writable value: 60
given: ramp coeff (r): 6080, Calibration frequency (r): 1875000Hz, T0: 3D, using LSE: 32000Hz
These values depend on your specific device and configuration, check your reference manual for more details */
HAL_DTS_Start_IT(&hdts);
HAL_DTS_GetTemperature(&hdts, &temp);
HAL_DTS_Stop_IT(&hdts);
|
hal_dts_handle_t hDTS;
int32_t temp;
HAL_DTS_Init(&hDTS, HAL_DTS);
hal_dts_config_t cfg = { .reference_clock = HAL_DTS_REFERENCE_CLOCK_PCLK,
.quick_measurement = HAL_DTS_QUICK_MEASUREMENT_DISABLE,
.high_speed_clock_division = 0 };
hal_dts_sensor_config_t sensor_cfg = { .trigger = HAL_DTS_TRIGGER_SOFTWARE,
.sampling_time = HAL_DTS_SAMPLING_TIME_1_CYCLE };
HAL_DTS_SetConfig(&hDTS, &cfg);
HAL_DTS_SetConfigSensor(&hDTS, HAL_DTS_SENSOR_1, &sensor_cfg);
/* Configure thresholds (degC) using dedicated API */
HAL_DTS_SetSensorThresholds(&hDTS, HAL_DTS_SENSOR_1, 100, 10);
/* Enable low threshold optional interrupt */
HAL_DTS_StartSensor_IT_Opt(&hDTS, HAL_DTS_SENSOR_1, HAL_DTS_OPT_IT_LOW_THRESHOLD);
HAL_DTS_GetSensorTemperature(&hDTS, HAL_DTS_SENSOR_1, &temp);
HAL_DTS_StopSensor_IT(&hDTS, HAL_DTS_SENSOR_1);
|
Key changes ¶
HAL2 configures thresholds in degrees Celsius using
HAL_DTS_SetSensorThresholds().HAL2 enables optional threshold interrupts using
HAL_DTS_StartSensor_IT_Opt().

